<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class APPS_Model extends CI_Model {

	public function __construct(){
		parent::__construct();
	}
	

	function result($sql, $all="rows") {
		$output = array();
		$rows	= array();
		$rsts	= $this->db->query($sql);

		if ($rsts->num_rows() > 0) {
			$rows = $rsts->result_array();
		}
		$rsts->free_result();

		if($rows) {
			switch ($all) {
				case "row":
				case 10:
					// single row
					$output = $rows[0];
					break;
				case "col":	
				case 11:
					// single first cell
					$key 	= array_keys($rows[0]);
					$output = $rows[0][$key[0]];
					break;
				default:
					$output = $rows;
					break;
			}
			unset($rows);
		}

		return $output;
	}
	
}
?>